﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>登录聊天室</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <div>
        <fieldset>
            <legend>登录聊天室</legend>
            <div>
                <input type="text" name="uername" id="username" value="" />
            </div>
            <div>
                <input type="password" name="password" id="password" value="" />
            </div>
            <div>
                <button id="login" type="button">登录</button>
            </div>
        </fieldset>
    </div>
    <script type="text/javascript">
        $(function () {
            var identityUrl = 'http://localhost:5000/connect/token';

            $('#login').click(function () {

                $.post(identityUrl, {
                    client_id: 'chat_client',
                    grant_type: 'password',
                    scope: 'openid chatapi profile offline_access',
                    username: $('#username').val(),
                    password: $('#password').val()
                }, function (result) {
                    if (result && result.access_token) {
                        sessionStorage['token'] = result.access_token;
                        window.location = "http://localhost:5001/chat.html";
                    }
                }, 'json');
            });
        });
    </script>
</body>
</html>